/*
 * Copyright (c) 2022, IMMORTA Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * - Neither the name of IMMORTA Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef RESET_DRV_H
#define RESET_DRV_H

/*!
 * @file reset_drv.h
 * @brief This file declares reset driver interfaces
 */

/*!
 * @addtogroup reset_drv
 * @{
 */

/*******Includes***************************************************************/
#include <stdbool.h>
#include "errcodes.h"

/*******Definitions************************************************************/
/*!
 * @brief Reset sources for reset control
 *
 * Note that POR and LVR are always enabled and unconfigurable
 */
#define RESET_CTRL_EPR          (0x00000004UL) /*!< EPR reset control */
#define RESET_CTRL_WDG          (0x00000008UL) /*!< WDG reset control */
#define RESET_CTRL_LOC          (0x00000010UL) /*!< LOC reset control */
#define RESET_CTRL_LOL          (0x00000020UL) /*!< LOL reset control */
#define RESET_CTRL_SW           (0x00000040UL) /*!< SW reset control */
#define RESET_CTRL_LOCKUP       (0x00000080UL) /*!< Lockup reset control */
#define RESET_CTRL_ACKERR       (0x00000100UL) /*!< ACK timeout error reset control */
#if (CONFIG_RESET_HSMERR_FEATURE == 1U)
#define RESET_CTRL_HSMERR       (0x00000200UL) /*!< HSM error reset control */
#endif

/*!
 * @brief Reset status flags
 */
#define RESET_FLAG_POR          (0x00000001UL) /*!< POR reset flag */
#define RESET_FLAG_LVR          (0x00000002UL) /*!< LVR reset flag */
#define RESET_FLAG_EPR          (0x00000004UL) /*!< EPR reset flag */
#define RESET_FLAG_WDG          (0x00000008UL) /*!< WDG reset flag */
#define RESET_FLAG_LOC          (0x00000010UL) /*!< LOC reset flag */
#define RESET_FLAG_LOL          (0x00000020UL) /*!< LOL reset flag */
#define RESET_FLAG_SW           (0x00000040UL) /*!< SW reset flag */
#define RESET_FLAG_LOCKUP       (0x00000080UL) /*!< Lockup reset flag */
#define RESET_FLAG_ACKERR       (0x00000100UL) /*!< ACK timeout error reset flag */
#if (CONFIG_RESET_HSMERR_FEATURE == 1U)
#define RESET_FLAG_HSMERR       (0x00000200UL) /*!< HSM error reset flag */
#endif

/*******APIs*******************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif

/*!
 * @brief Enable or disable reset function of reset sources
 *
 * @param[in] resetControl: Reset control sources, see definition of RESET_CTRL_XX macros
 *                          User can enable/disable one or more reset sources once
 *                          Eg: RESET_CTRL_EPR, or (RESET_CTRL_EPR | RESET_CTRL_WDG | ...)
 * @param[in] enable: true: Enable reset function
 *                    false: Disable reset function
 * @return None
 */
void RESET_SetEnable(uint32_t resetControl, bool enable);

/*!
 * @brief Get all reset status flags
 *        User can check if the expected flag is set by operation '&' with its return value
 *        Eg: if (retValue & RESET_FLAG_POR) != 0, RESET_FLAG_POR is set
 *
 * @param[in] None
 * @return Reset status flags
 */
uint32_t RESET_GetStatusFlags(void);

/*!
 * @brief Clear reset status flags
 *
 * @param[in] resetFlag: Reset flag sources, see definition of RESET_FLAG_XX macros
 *                       User can clear one or more reset flags once
 *                       Eg: RESET_FLAG_POR, or (RESET_FLAG_POR | RESET_FLAG_LVR | ...)
 * @return None
 */
void RESET_ClearStatusFlags(uint32_t resetFlag);

/*!
 * @brief Enable or Disable filter of external reset pin (RESET_b)
 *
 * @param[in] enable: true: Enable filter
 *                    false: Disable filter
 * @return None
 */
void RESET_SetFilterEnable(bool enable);

/*!
 * @brief Configure filter deglitch width of external reset pin (RESET_b)
 *
 * @param[in] filterWidth: Filter deglitch width
 * @return None
 */
void RESET_ConfigFilterWidth(uint16_t filterWidth);

#if defined(__cplusplus)
}
#endif

/*! @} */

#endif /* RESET_DRV_H */

/*******EOF********************************************************************/

